exports.categoryDetail = function(req,res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;
     //任务流创建
     async.waterfall([

        //获取该分类下的文章
        function(cb){

            // //console.log(CORE_APIConfig.coreAPI.searchForumContentAndUserInfo + "/fc_fcid/" +restfulParams.fc_id+ "/sort_order/fc_id-desc" + "/skip/" + skip + "/limit/" + limit)

            R.SEND_HTTP(
                req,
                {
                    url    : CORE_APIConfig.coreAPI.searchForumContentAndUserInfo + "/fc_fcid/" +restfulParams.fc_id+ "/sort_order/fc_id-desc" + "/skip/" + skip + "/limit/" + limit,
                    method : 'GET',
                    data   : {
                        fields : [
                            "fc_id",
                            "fc_title",
                            "fc_fcid",
                            "fc_title",
                            "fc_images",
                            "fc_type",
                            "fc_browse_count",
                            "fc_create_time",
                            "u_nickname",
                            "u_header_url"
                        ].join(",")
                    }
                },
                function (err, data) {
                    
                    resultData.contentData = data.data;
                    
                    cb();
                }
			);
        },
        //获取分类详细信息
         function(cb){

             R.SEND_HTTP(
                 req,
                 {
                     url    : CORE_APIConfig.coreAPI.searchCategory + "/fc_id/" +restfulParams.fc_id,
                     method : 'GET',
                 },
                 function (err, data) {

                     resultData.categoryDetail = data.data;

                     cb();
                 }
             );
         },
         //获取分类详细信息
         function(cb){

             R.SEND_HTTP(
                 req,
                 {
                     url    : CORE_APIConfig.coreAPI.searchForumContent + "/fc_fcid/" +restfulParams.fc_id,
                     method : 'POST',
                     data:{
                         fields:['fc_uid'].join(",")
                     }
                 },
                 function (err, data) {

                     // resultData.userID = data.data;

                     var userID = data.data;
                     var userInfo = [];
                     for(var i=0;i<userID.length;i++){
                         var id = userID[i].fc_uid;
                         userInfo.push(parseInt(id));
                     }
                     Array.prototype.distinct = function (){
                         var arr = this,
                             i,
                             j,
                             len = arr.length;
                         for(i = 0; i < len; i++){
                             for(j = i + 1; j < len; j++){
                                 if(arr[i] == arr[j]){
                                     arr.splice(j,1);
                                     len--;
                                     j--;
                                 }
                             }
                         }

                     };
                     userInfo.distinct();

                     resultData.userJoinCount = userInfo.length;

                     cb();
                 }
             );
         },
         //获取子分类列表
         function(cb){

             R.SEND_HTTP(
                 req,
                 {
                     url    : CORE_APIConfig.coreAPI.searchCategory + "/fc_fid/" +restfulParams.fc_id,
                     method : 'GET',
                 },
                 function (err, data) {

                     resultData.soncategoryDetail = data.data;

                     cb();
                 }
             );
         },
         //获取父分类
         function(cb){

             R.SEND_HTTP(
                 req,
                 {
                     url    : CORE_APIConfig.coreAPI.searchCategory + "/fc_id/" +resultData.categoryDetail[0].fc_fid,
                     method : 'POST',
                     data   : {
                         fields : [
                             "fc_name",
                         ].join(",")
                     }
                 },
                 function (err, data) {

                     resultData.fatherCategoryDetail = data.data;

                     cb();
                 }
             );
         },
         //查询被邀请次数
         function (cb) {

             R.SEND_HTTP(
                 req,
                 {
                     url: CORE_APIConfig.coreAPI.artInviteLogContent + "/count/1/fil_invite_type/1/fil_is_read/0/fil_fid/" + restfulParams.u_id,
                     method: 'POST',
                     data: {
                         fields: ["fil_id"].join(",")
                     }
                 },
                 function (err, data) {

                     resultData.invitedCount = data.count;

                     cb();
                 }
             );
         },
        //数据转化
        function(cb){

            for(var i = 0 ;i<resultData.contentData.length;i++){

                //日期转化
                resultData.contentData[i].fc_create_time_value = common.getDateDiff(resultData.contentData[i].fc_create_time);
                
                //类型显示转化
                if(resultData.contentData[i].fc_type == 0){
                   resultData.contentData[i].fc_type_value = "艺问答";
                }else{
                   resultData.contentData[i].fc_type_value = "谈艺谈";
                }

                if(resultData.contentData[i].u_header_url == null || resultData.contentData[i].u_header_url == ""){
                   resultData.contentData[i].u_header_url = config.publicConfig.defaultHeaderUrl;
                }

                //处理图片数量
                var imagesArr = resultData.contentData[i].fc_images.split("|");
                resultData.contentData[i].imagesData = imagesArr; 
            }

            cb();

        }

    ],function(err, result){
           
        //返回最终拼接结果
        RES.response(res,true,resultData);
    
    });

}